package com.md.controller;

import com.md.entity.DeptInfo;
import com.md.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@ResponseBody
@RequestMapping(produces = "application/json;charset=utf-8")
public class DeptController {
    @Autowired
    private DeptService deptService;
    @RequestMapping("selectAll")
    @ResponseBody
    List<DeptInfo> selectAll() {
        return deptService.selectAll();
    }

    @RequestMapping("selectById")
    DeptInfo selectById(int did) {
        DeptInfo info = deptService.selectById(did);
        return info!=null?info:new DeptInfo(0,"无人");
    }

    @RequestMapping("deleteById")
    String deleteById(int did) {
        return deptService.deleteById(did)>0?"成功":"失败";
    }

    @RequestMapping("inserts")
    String inserts(DeptInfo deptInfo) {
        return deptService.inserts(deptInfo)>0?"成功":"失败";
    }

    @RequestMapping("updates")
    String updates(DeptInfo deptInfo) {
        return deptService.updates(deptInfo)>0?"成功":"失败";
    }

    @RequestMapping("selectByName")
    List<DeptInfo> selectByName(String dname) {
        return deptService.selectByName(dname);
    }
}
